package cn.lianxi.kaoshi._10_;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

//s01 jack M 10000 -- <"M", "s01 jack M 10000">
//MAP -- map() -- partition()

public class MySelfPartitioner extends Partitioner<Text, Text> {

	@Override
	public int getPartition(Text key, Text value, int numPartitions) {

		char first = key.toString().charAt(0);

		// return ((first >= 'a' && first <= 'z') ? 0
		// : ((first >= 'A' && first <= 'Z') ?: 1)) % numPartitions;
		// 不会三目运算符的简写形式,就是两个三木运算符写在一起,然后里边的我只要一个,怎么省略 ? 或者是 : 后边的内容
		if (first >= 'a' && first <= 'z') {
			return 0 % numPartitions;
		} else if (first >= 'A' && first <= 'Z') {
			return 1 % numPartitions;
		} else {
			return 2;
		}
	}
}
